/**
 * @create 2022-04-07
 * @desc interface
 */

import React from 'react';
import { TableProProps, TableCompColumnProps } from '../components/table/interface';

type GetRowKey<RecordType> = (record: RecordType, index?: number) => React.Key;
export type ProTableColumnProps<T> = TableCompColumnProps<T>;

export interface ProTableParams {
  pagination?: {
    current: number;
    pageSize: number;
  };
}

export type FetcherType<T = any, Q extends Record<ObjectKey, any> = any> = (
  params: ProTableParams & Q,
) => Promise<undefined | ProTableDataType<T>>;

export interface ProTableProps<
  T extends Record<string, any>,
  P extends Record<ObjectKey, any> = any,
> {
  params?: P; // 自定义参数，当参数变化时会重新发送请求，参数会传递到 fetcher 中
  fetcher?: FetcherType<T, P>;
  rowKey?: string | GetRowKey<T>;
  table: TableProProps<T>; // ant-design table props
  fillPage?: boolean; // 占满整个父元素，让分页停留在页面最下方， 默认 true
  TopBlock?: React.ReactNode;
}

export interface ProTableDataType<T> {
  data?: T[];
  total?: number;
  [key: string]: any;
}
